package com.whfp.coky.ble.model

import android.os.Parcel
import android.os.Parcelable
import com.tencent.mmkv.MMKV
import com.whfp.afs330h_sdk.utils.RxHexTool
import com.whfp.coky.other.Constants

/**
 *
 *
 * created by coky on 2022/4/8
 */
class PhyEviModel {
    companion object{
        //物证箱设备用到的服务
        val WZX_SERVICE_UUID = "0000ab00-0000-1000-8000-00805f9b34fb"
        //物证箱设备用到的通知特征
        val WZX_CHARACTERISTIC_NOTIFY_UUID = "0000ab02-0000-1000-8000-00805f9b34fb"
        //物证箱设备用到的写入特征
        val WZX_CHARACTERISTIC_WRITE_UUID = "0000ab01-0000-1000-8000-00805f9b34fb"

        /**
         * 指令头
         */
        val instruction0 = "a500" //调试升级
        val instruction1 = "a501" //获取物证箱ID
        val instruction2 = "a502" //获取物证箱状态
        val instruction3 = "a503" //物证箱开锁
        val instruction4 = "a504" //物证箱关锁
        val instruction5 = "a505" //物证箱开始押运
        val instruction6 = "a506" //ACK帧，接收应答


        /**
         * 指令意义
         */
        val OPEN_SUCCESS = "00" //开箱成功
        val OPEN_FAILED = "01" //开箱失败
        val TRANS_SUCCESS = "00" //押运成功
        val TRANS_FAILED = "01" //押运失败
        val STATUS_TRANS_OFF = "00" //未押运
        val STATUS_TRANS_ON = "01" //押运中
        val STATUS_LOC_GPS = "00" //gps定位
        val STATUS_LOC_4G = "01" //基站定位
        val STATUS_NET_NO_CARD = "00" //无卡
        val STATUS_NET_NO_SIGN = "01" //无信号
        val STATUS_NET_NO_SERVICE = "02" //无服务
        val STATUS_NET_NORMAL = "03" //正常



        private var userId = ""//16进制字符串

//        0-3:头，4-5：帧id，6-7：帧数，8-9：用户id长度，10-？：用户id
        fun buildIDCode():String{
            buildUserId()
            return StringBuilder(instruction1)
//                .append(getZId())
//                .append(getZx())
//                .append(userId.length)
//                .append(userId)
                .toString()
        }

       private fun buildUserId(){
            if (userId.isEmpty()){
                userId = RxHexTool.str2HexStr(MMKV.defaultMMKV().decodeString(Constants.USER_ID,"1234")!!)
            }
        }

    }


    class StatusBean() : Parcelable {
        //PWR: 电量百分比，满电量100
        var pwr: String? = null

        //DB: 信号强度，实际信号强度+150
        var db: String? = null

        //JD: 实际经度值*1000000发送 ，高字节在前(0表示没有获取到)
        var jd: String? = null

        //WD: 实际值*1000000发送， 高字节在前(0 表示没有获取到)
        var wd: String? = null

        //S0:箱体状态 00：空闲状态 01：押运状态
        var s0: String? = null

        //S1：定位状态00：GPS定位 01：基站定位
        var s1: String? = null

        //S2：网络状态 00：无卡 01：无信号 02：无服务 03：正常
        var s2: String? = null

        constructor(parcel: Parcel) : this() {
            pwr = parcel.readString()
            db = parcel.readString()
            jd = parcel.readString()
            wd = parcel.readString()
            s0 = parcel.readString()
            s1 = parcel.readString()
            s2 = parcel.readString()
        }

        override fun writeToParcel(parcel: Parcel, flags: Int) {
            parcel.writeString(pwr)
            parcel.writeString(db)
            parcel.writeString(jd)
            parcel.writeString(wd)
            parcel.writeString(s0)
            parcel.writeString(s1)
            parcel.writeString(s2)
        }

        override fun describeContents(): Int {
            return 0
        }

        companion object CREATOR : Parcelable.Creator<StatusBean> {
            override fun createFromParcel(parcel: Parcel): StatusBean {
                return StatusBean(parcel)
            }

            override fun newArray(size: Int): Array<StatusBean?> {
                return arrayOfNulls(size)
            }
        }


    }
}